import time
from os import times
from selenium.webdriver.support import expected_conditions as ec

import allure
from selenium.common import TimeoutException
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait

from base.webkeys import WebKeys
from locator.allPages_data import *


class Opportunity_detailsPage(WebKeys):
    def opportunity_details(self):
        # 点击机会tab
        with allure.step("点击机会tab"):
            self.on_click(*the_Opportunity_tab)
        with allure.step("按存量空户内的报单没有交易权限进行筛选"):
            # 点击存量空户
            with allure.step("点击存量空户"):
                locator = ("xpath", '//*[@id="index"]/div[2]/div/div[2]/div/div/div/div[1]/div/div[4]')
                self.locator_with_wait(*locator).click()
            with allure.step("点击报单没有交易权限"):
                #等待遮罩消失
                WebDriverWait(self.driver, 30).until(
                    ec.invisibility_of_element_located((By.CLASS_NAME, "var-loading__content-mask"))
                )
                # WebDriverWait(self.driver, 30).until(
                #     lambda driver: len(driver.find_elements(By.CLASS_NAME, "var-loading__content-mask")) == 0)
                #点击报单没有交易权限
                locator = ("xpath", '//*[@id="index"]/div[2]/div/div[2]/div/div/div/div[2]/div[2]/div[2]/div[2]/div[1]')
                self.locator_with_wait(*locator).click()
        with allure.step("点击刘九四12340525报单没有交易权限"):
            locator = ("xpath", "//*[contains(text(),'12340525')]")
            self.locator_with_wait(*locator).click()
        with allure.step("点击商机处置"):
            locator = ("xpath",  "//*[text()='商机处置']")
            self.locator_with_wait(*locator).click()
        with allure.step("判断提交跟进按钮成功显示在页面"):
            locator = ("xpath",  "//*[text()='提交跟进']")
            result=self.get_text(*locator)
        return result